package com.avantis.common.entity;

import com.avantis.common.entity.base.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * @ClassName Role
 * @Description TODO
 * @Author kirago
 * @Date 2018/11/26 19:04
 * @Version 1.0
 **/
@Entity
@Table(name = "k_role")
@Data
public class Role extends BaseEntity implements Serializable {

	@Column(unique = true,nullable = false)
	private String name;

	//角色描述
	private String description;

	//角色与用户的关联关系
	@JsonIgnore
	@ManyToMany(mappedBy = "roles")
	private Set<AdminUser> adminUsers = new HashSet<>();

	//角色与权限的关联关系
	@JsonIgnore
	@JoinTable(name = "k_role_permission",
			joinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "id")},
			inverseJoinColumns = {@JoinColumn(name = "permissions_id",referencedColumnName = "id")})
	@ManyToMany(cascade = CascadeType.ALL)
	private Set<Permission> permissions = new HashSet<>();

}